package com.cgc.web.action;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.fastjson.JSON;
import com.cgc.entity.Emp;
import com.cgc.service.EmpService;
import com.cgc.utils.ReturnJson;

public class EmpAction extends BaseAction<Emp> {
	
	public EmpService empService;
	
	public String oldPwd;//旧密码
	
	public String newPwd;//新密码

	public EmpService getEmpService() {
		return empService;
	}

	@Autowired
	public void setEmpService(EmpService empService) {
		this.empService = empService;
		super.setBaseService(this.empService);
	}
	/**
	 * 修改密码
	 */
	public void updatePwd(){
		//旧密码是否正确
		Emp emp = (Emp) getRequest().getSession().getAttribute("loginUser");
		Map<String, Object> rtn = new HashMap<String, Object>();
		if(null!=emp){
	    	String pwd = emp.getPwd();
	    	if(pwd.equals(oldPwd)){
	    		empService.updatePwd(emp.getId(), pwd);
	    		rtn.put("success", true);
	    		rtn.put("message", "修改密码成功");
	    	}else{
	    		rtn.put("success", false);
	    		rtn.put("message", "输入的旧密码不正确");
	    	}
	    }
		ReturnJson.writejson(JSON.toJSONString(rtn), getResponse());
	
	}

	public String getOldPwd() {
		return oldPwd;
	}

	public void setOldPwd(String oldPwd) {
		this.oldPwd = oldPwd;
	}

	public String getNewPwd() {
		return newPwd;
	}

	public void setNewPwd(String newPwd) {
		this.newPwd = newPwd;
	}
	
	

}
